package org.cerberus.platform.internal.impl;

import java.io.IOException;

import org.cerberus.platform.internal.IEventQueue;
import org.cerberus.platform.internal.IInternalPlatform;
import org.cerberus.platform.internal.IProtocol;
import org.cerberus.platform.internal.domain.IComponentClass;

public class EventQueueProtocolWrapper implements IProtocol {

	private IEventQueue queue;
	private IInternalPlatform platform;
	
	public EventQueueProtocolWrapper(IInternalPlatform platform) {
		this.platform = platform;
		this.queue = platform.getEventQueue();
	}
	
	@Override
	public void change(Integer objectId, int index, int attributeCount, Object value) {
		queue.postEvent(new ChangeRunnable(objectId, index, attributeCount, value));
	}

	@Override
	public void command(int commandID) throws IOException {
		
	}

	@Override
	public void newClass(IComponentClass clazz) throws IOException {
		
	}

	@Override
	public void newObject(Object[] object) throws IOException {
		
	}

	@Override
	public void parameter(String key, String value) {
		
	}

	@Override
	public void removeClass(String classID) throws IOException {
		
	}

	@Override
	public void removeObject(Integer id) throws IOException {
		
	}

	@Override
	public void restore() throws IOException {
		
	}

	private final class ChangeRunnable implements Runnable {
		
		private final Integer objectId;
		private final int index;
		private final int attributeCount;
		private final Object value;

		public ChangeRunnable(Integer objectId, int index, int attributeCount, Object value) {
			this.objectId = objectId;
			this.index = index;
			this.attributeCount = attributeCount;
			this.value = value;
		}
		
		@Override
		public void run() {
			platform.getRequest().change(objectId, index, attributeCount, value);
		}
		
	}
	
}
